package topo.table;

import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;

public class ScrollTablePane extends JScrollPane {
    TableMouseHandle handle;
    private ObjectTable table;

    public ScrollTablePane(ObjectTable table) {
        super(table);
        setAutoscrolls(true);
        this.table = table;

        addMouseListener(new ScrollTablePane_this_mouseAdapter());
    }

    public ObjectTable getObjectTable() {
        return this.table;
    }

    public ObjectTableModel getObjectTableModel() {
        return this.table.getObjectTableModel();
    }

    void myMouseReleased(MouseEvent e) {
        if (this.handle == null) {
            return;
        }

        if (e.getButton() == 3) {
            JPopupMenu menu = this.handle.createBlankMenu(e);
            menu.show((Component) e.getSource(), e.getX(), e.getY());
        }
    }

    public void setMouseHandle(TableMouseHandle theHandle) {
        this.handle = theHandle;
        this.table.setMouseHandle(this.handle);
    }

    class ScrollTablePane_this_mouseAdapter extends MouseAdapter {
        ScrollTablePane_this_mouseAdapter() {
        }

        public void mouseReleased(MouseEvent e) {
            ScrollTablePane.this.myMouseReleased(e);
        }
    }
}